<?php

namespace App\Admin\Controllers;

use App\Models\SmsCode;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class SmsCodeController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('短信验证码');
            $content->description('description');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('header');
            $content->description('description');

            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(SmsCode::class, function (Grid $grid) {
            $grid->disableCreation();
            $grid->actions(function ($actions) {
                $actions->disableEdit();
            });
            $grid->id('ID')->sortable();
            $grid->phone_number('手机号');
            $grid->code('验证码');
            $grid->status('状态')->display(function ($data){
                return $data?'已使用':'未使用';
            });
            $grid->ctime('发送时间')->display(function ($data){
               return $data?date('Y-m-d H:i:s',$data):'';
            });

        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(SmsCode::class, function (Form $form) {

            $form->display('id', 'ID');


        });
    }
}
